package com.fbr.bannerplayer;


import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

import java.util.ArrayList;
import java.util.List;

//import butterknifefe.BindView;
//import butterknife.ButterKnife;
//import butterknife.OnClick;
//import butterknife.Unbinder;
//import butterknife.ButterKnife;
//import butterknife.Unbinder;
import cn.bannerplayerlibrary.BannerConfig;
import cn.bannerplayerlibrary.PlayerBanner;
import cn.bannerplayerlibrary.WeakHandler;
import cn.bannerplayerlibrary.data.BannerData;
import cn.bannerplayerlibrary.data.UrlBannerData;
import cn.bannerplayerlibrary.view.PlayAttrs;
import cn.bannerplayerlibrary.view.newbanner.NewBannerPlayerView;
import cn.bannerplayerlibrary.view.newbanner.NewPlayerBanner;
import dlcpermissionlibrary.PermissionCallback;
import dlcpermissionlibrary.PermissionUtil;

public class MainActivity extends AppCompatActivity {
    //    @BindView(R.id.banner)
    NewPlayerBanner mBanner;
    NewPlayerBanner mBanner2;
    //    private PlayAttrs mPlayAttrs = new PlayAttrs();
//    private WeakHandler mHandler = new WeakHandler();
    private ArrayList<BannerData> mBannerData;
    private ArrayList<BannerData> mBannerData2;
    private String[] mStrings;
    //    private List<String> mStrings;
//    private Unbinder mUnbinder;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mBanner = findViewById(R.id.banner);
        mBanner2 = findViewById(R.id.banner2);
//        mUnbinder = ButterKnife.bind(this);
        mStrings = new String[]{
                "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=133188088,2844766010&fm=26&gp=0.jpg",
//                "http://szykkfj.app.xiaozhuschool.com/public/uploads/imgs/20190525/d9ec36d48962cef4f07363c5de838920.jpg",
//                "http://szykkfj.app.xiaozhuschool.com/public/uploads/imgs/20190525/b615b496832755301fb82d0042cb6fff.jpg",
//                "http://szykkfj.app.xiaozhuschool.com/public/uploads/imgs/20190328/ea7a173059bf15698d18ad2000ea646e.jpg",
//                "http://szykkfj.app.xiaozhuschool.com/public/uploads/imgs/20190525/9b74e55ac9e2f7a18d77bb4b92f1ab4a.jpg",
//                "http://szykkfj.app.xiaozhuschool.com/public/uploads/imgs/20190529/6a55dc85757ec2c0da23b98d006e0af2.jpg",
//                "http://szykkfj.app.xiaozhuschool.com/public/uploads/imgs/20190529/48d703da5aef894206ba9790522c3453.jpg",
//                "http://szykkfj.app.xiaozhuschool.com/public/uploads/imgs/20190529/c6a1488274266e7c74b444f158b99239.jpg"
        };

        mStrings = new String[]{
                "http://hnshg.a.xiaozhuschool.com/statics/images/2019-06-17/15607536991960.mp4",
                "http://szykkfj.app.xiaozhuschool.com/public/uploads/imgs/20190328/ea7a173059bf15698d18ad2000ea646e.jpg",
                "http://mengyi.sxitdlc.com/public/uploads/imgs/20190404/a1b3590fc03a5a745494df1958a65925.mp4",
//                "http://szykkfj.app.xiaozhuschool.com/public/uploads/imgs/20190525/9b74e55ac9e2f7a18d77bb4b92f1ab4a.jpg",
//                "http://szykkfj.app.xiaozhuschool.com/public/uploads/imgs/20190529/6a55dc85757ec2c0da23b98d006e0af2.jpg",
                "http://mengyi.sxitdlc.com/public/uploads/video/20190417/402dd1e51d384aed8bf647e0c5f8262e.mp4",
                "http://mengyi.sxitdlc.com/public/uploads/video/20190417/c473f9fcef16561bd1011fb1a2921210.mp4",
//                "http://szykkfj.app.xiaozhuschool.com/public/uploads/imgs/20190529/48d703da5aef894206ba9790522c3453.jpg",
                "http://mengyi.sxitdlc.com/public/uploads/video/20190429/47259e7c21e16a5ff3f48d9a22f48b77.mp4"
        };
        mBannerData = new ArrayList<>();
        mBannerData2 = new ArrayList<>();
        for (String url : mStrings) {
            mBannerData.add(new UrlBannerData(url));
            mBannerData2.add(new UrlBannerData(url));
        }
        PermissionUtil.getInstance(getApplicationContext()).requestAllDynamicPermissons(this, new PermissionCallback.TwoMethodCallback() {
            @Override
            public void onSuccessCallback(String[] successPermissions) {
                mBanner.setBannerIndicatorStyle(BannerConfig.NOT_INDICATOR);
                mBanner.setTag("setBannerIndicatorStyle");
                mBanner.setBannerData(mBannerData);
                mBanner.prepare();
                mBanner.resumePlay();

                mBanner2.setBannerIndicatorStyle(BannerConfig.NOT_INDICATOR);
                mBanner2.setTag("setBannerIndicatorStyle2");
                mBanner2.setBannerData(mBannerData2);
                mBanner2.prepare();
                mBanner2.resumePlay();
            }

            @Override
            public void onDeniedCallback(String[] deniedPermissions) {
//                spm("onDeniedCallback"+Arrays.toString(deniedPermissions));
//                spm("getPermissionsTip"+PermissionString.getInstance().getPermissionsTip(deniedPermissions));
            }
        });
        findViewById(R.id.btn_reset).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int count = (int) (Math.random() * (mStrings.length + 1));

                mBanner.update(mBannerData.subList(0, count));
                mBanner2.update(mBannerData.subList(0, count));
            }
        });findViewById(R.id.btn_pausePlay).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mBanner.pausePlay();
                mBanner2.pausePlay();
            }
        });
        findViewById(R.id.btn_resumePlay).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mBanner.resumePlay();
                mBanner2.resumePlay();
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
//        if (mUnbinder != null) {
//            mUnbinder.unbind();//在页面销毁时解绑
//        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        mBanner.pausePlay();
        mBanner2.pausePlay();
    }

    @Override
    protected void onResume() {
        super.onResume();
        mBanner.resumePlay();
        mBanner2.resumePlay();
    }



}
